<?php
// +----------------------------------------------------------------------
// | Action ：投票管理
// +----------------------------------------------------------------------
// | DateTime：2015年12月8日
// +----------------------------------------------------------------------
// | Author: Danson <zoudan916@163.com>
// +----------------------------------------------------------------------

namespace Admin\Controller;

class LordController extends AdminController{

    /* 群猪列表 */
    public function index(){
        if(isset($_GET['charge'])){
            $where['lord_name']    =   array('like', '%'.(string)I('charge').'%');
            $where['user_name']    =   array('like', '%'.(string)I('charge').'%');
            $where['_logic'] = 'or';
            $map['_complex'] = $where;
        }
        $map['lord_id'] = array('neq',1);
        $list = $this->lists('lord_user',$map,'create_time desc');
        $this->assign('list',$list);
        $this->display();
    }

    /* 更新 */
    public function user_save(){
        if(IS_POST){

        }
        $id = I('get.id',0,'intval');
        $info = M('lord_user')->where(array('lord_id'=>$id))->find();
        $this->assign('info',$info);
        $this->display('save');
    }

    /* 删除 */
    public function user_del(){
        $bannerModel = D('lord_user');
        $ids = array_unique((array)I('ids',0));
        if(empty($ids)){
            $this->error('请选择需要删除的数据');
        }else{
            $condition = array('lord_id'=>array('in',$ids));
            if($bannerModel->where($condition)->delete()){
                $this->success('操作成功');
            }else{
                $this->error('服务器异常,请稍后再试!');
            }
        }
    }

    /* 投票粉丝 */
    public function voet(){
        if(isset($_GET['charge'])){
            $_GET['nickname'] = array('like', '%' .$_GET['charge']. '%');
        }
        $map['lord_id'] = I('get.lord_id',0,'intval');
        $list = $this->lists('lord_voet',$map);
        $this->assign('list',$list);
        $this->display();
    }

    /* 审核 */
    public function check(){
        $bannerModel = D('lord_user');
        $ids = array_unique((array)I('ids',0));
        if(empty($ids)){
            $this->error('请选择需要审核的数据');
        }else{
            foreach($ids as $k){
                $result = $bannerModel->where(array('lord_id'=>$k))->save(array('check'=>1));
                if(!$result){
                    break;
                    $this->error('服务器异常,请稍后再试!');
                }
            }
            $this->success('操作成功');
        }
    }
}